import { computed } from "vue";
import { useUserStore } from "@/stores/user";
import { ILoginInfo } from "@/types";
import { auth } from "@/api/user";

// 登录、登出、获取用户信息
export function useAuth() {
    const store = useUserStore()
    const user = computed(() => store.getUserInfo)
    const login = async (data: ILoginInfo) => {
      const { token, userInfo } = await auth(data)
      store.setInfo({ token, userInfo })
    }
    const logout = () => {
      store.removeInfo()
    }
    return {
      user,
      login,
      logout,
    }
  }
  

